import {observable, action} from 'mobx';
import _ from 'lodash';
import {message} from 'antd';
import {toJSDeep} from '../store/Store';

interface PagiNation {
    defaultCurrent: number;
    showQuickJumper?: boolean;
    showSizeChanger?: boolean;
    current: number;
    pageSize: number;
    showTotal?: any;
    total: number;
    pageSizeOptions?: Array<string>
}

interface Sorter{
    order: string;
    field: string;
}

export class ListStore<T> {
    @observable _SpiLoading:boolean = false; //页面加载loading
    @observable _RefreshLoading:boolean = false;   //刷新按钮loading
    @observable data:Array<T> = [];
    @observable pagination:PagiNation = {
        defaultCurrent:1,
        showSizeChanger:true,
        showQuickJumper:true,
        current:1,
        pageSize:20,
        total: 0,
        showTotal:(total)=> `共 ${total} 条记录`
    };

    @action searchCallback(res){
        if(res.success){
            let data = res.result;
            let pagination = this.pagination;
            this.pagination = _.assign(pagination,{
                total: data.total,
                pageSize: data.pageSize,
                current: data.pageNumber});
            this.data = data.list;
        }else{
            message.error(res.message,3);
        }
        
        this._SpiLoading = false;
        this.changeState(false);
    }

    @action changeState(params){
        this._RefreshLoading = params;
    }
}